package fr.jer.guideo;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.csvreader.CsvReader;

public abstract class FakeDatas {
	public static PP generateGfiPP() {
		return new PP("GFI", EnumTypePP.monument, "43.578401", "1.362727");
	}

	public static PP generateCapPP() {
		return new PP("Cap Gemini", EnumTypePP.restaurant, "43.579241",
				"1.368177");
	}

	public static List<PP> generateListPP() {
		List<PP> res = new ArrayList<PP>();
		res.add(generateGfiPP());
		res.add(generateCapPP());
		return res;
	}

	public static List<PP> useMuseeCsv() {
		List<PP> res = new ArrayList<PP>();
		CsvReader musee;
		String trace = null;
		try {
			File file = new File("/var/www/Musee.csv");
			trace = file.getAbsolutePath();
			if (file.isFile()) {
				musee = new CsvReader("/var/www/Musee.csv", ';');
				musee.readHeaders();
				while (musee.readRecord()) {
					String longitude = musee.get("X_WGS84");
					String latitude = musee.get("Y_WGS84");
					String titre = musee.get("Description");
					res.add(new PP(titre, EnumTypePP.musee, latitude, longitude));
				}
				musee.close();
			} else {
				res.add(new PP("trace", EnumTypePP.musee, trace, ""));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return res;
	}

	public static List<PP> useMuseeNextGenCsv() {
		List<PP> res = new ArrayList<PP>();
		CsvReader musee;
		String trace = null;
		try {
			File file = new File("/var/www/museeNextGen.csv");
			trace = file.getAbsolutePath();
			if (file.isFile()) {
				musee = new CsvReader("/var/www/museeNextGen.csv", ';');
				musee.readHeaders();
				while (musee.readRecord()) {
					String longitude = musee.get("longitude");
					String latitude = musee.get("latitude");
					String titre = musee.get("titre");
					String typeString = musee.get("type");
					EnumTypePP type = EnumTypePP.inconnu;
					if (typeString != null) {
						type = EnumTypePP.valueOf(typeString.toLowerCase());
					}
					String description = musee.get("description");
					String wikipedia = musee.get("wikipedia");
					res.add(new PP(titre, type, latitude, longitude,
							description, wikipedia));
				}
				musee.close();
			} else {
				res.add(new PP("trace", EnumTypePP.inconnu, trace, ""));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return res;
	}
}
